package com.android.demp;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

public class MainDemo extends Activity {
	String items[]={ "item1", "item2", "item3" };
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.mainlayout);
		String items2[]= { "option1", "option2" };
		MyCustomAdapter adapter = new MyCustomAdapter(this,
				R.layout.main_list_item, items);
		MyCustomAdapter adapter1 = new MyCustomAdapter(this,
				R.layout.main_list_item, items2);
		ListView listView = (ListView) findViewById(R.id.ListView01);
		listView.setAdapter(adapter);
		ListView listView1 = (ListView) findViewById(R.id.ListView02);
		listView1.setAdapter(adapter1);
	}
	
	public class MyCustomAdapter extends ArrayAdapter<String> {
		Context context;
		boolean check=false;
		public MyCustomAdapter(Context context, int textViewResourceId, String[] objects) {
			super(context, textViewResourceId, objects);
			if(objects.equals(items))
			{
				check=true;
			}
			this.context = context;
			// TODO Auto-generated constructor stub
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			View view= convertView;
			if(view==null)
			{
				LayoutInflater inflater = (LayoutInflater) this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
				view = inflater.inflate(R.layout.main_list_item, parent, false);
				ImageView image1=(ImageView)view.findViewById(R.id.ImageView01);
				TextView text=(TextView)view.findViewById(R.id.TextView01);
				if(check)
				{
					if(position==0)
					{
						text.setText("Words");
						//image1.setImageResource(R.drawable.book);
			            text.setClickable(true);
			            text.setOnClickListener(new View.OnClickListener() {
			                public void onClick(View view) {
			                    Intent myIntent = new Intent(view.getContext(), VocDemo.class);
			                   startActivityForResult(myIntent, 0);
			                }
			            });
					}
					if(position==1)
					{
						text.setText("Item2");
						//image1.setImageResource(R.drawable.book);
					}
					if(position==2)
					{
						text.setText("Item3");
						//image1.setImageResource(R.drawable.book);
					}
				}
				else
				{
					if(position==0)
					{
						text.setText("Option1");
						//image1.setImageResource(R.drawable.book);
					}
					if(position==1)
					{
						text.setText("Option2");
						//image1.setImageResource(R.drawable.book);
					}
				}
			}
		    return view;
		}
	}

}
